package com.xxx.config.exception.support;

import com.xxx.config.exception.ErrorResponseStatusCode;
import com.xxx.config.exception.GenExceptCode;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;

/**
 * 未捕获的异常解析
 *
 * @version 1.0
 * @since 1.0
 */
public class UncaughtExceptionMapperSupport implements ExceptionMapper<Throwable> {
    @Override
    public Response toResponse(Throwable throwable) {
        String json = "{" + "code" + ":\"" + GenExceptCode.System_Error.name() + "\"," + "msg" + ":\"" + throwable.getMessage() + "\"}";
        return Response.status(ErrorResponseStatusCode.SYSTEM_ERROR).entity(json).type(MediaType.APPLICATION_JSON).build();
    }
}
